package com.aidl.demo.ui.activity;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.aidl.demo.R;
import com.aidl.demo.entity.Video;
import com.aidl.demo.utils.AutoMarqueeTextView;
import com.aidl.demo.utils.Constant;
import com.bumptech.glide.Glide;
import com.zhy.autolayout.AutoRelativeLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/4/19 0019.
 */

public class MovieActivivty extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.img_movie1)
    ImageView imgMovie1;
    @BindView(R.id.movie_rl1)
    AutoRelativeLayout movieRl1;
    @BindView(R.id.img_movie2)
    ImageView imgMovie2;
    @BindView(R.id.movie_rl2)
    AutoRelativeLayout movieRl2;
    @BindView(R.id.img_movie3)
    ImageView imgMovie3;
    @BindView(R.id.movie_rl3)
    AutoRelativeLayout movieRl3;
    @BindView(R.id.img_movie4)
    ImageView imgMovie4;
    @BindView(R.id.movie_rl4)
    AutoRelativeLayout movieRl4;
    @BindView(R.id.img_movie5)
    ImageView imgMovie5;
    @BindView(R.id.movie_rl5)
    AutoRelativeLayout movieRl5;
    @BindView(R.id.img_movie6)
    ImageView imgMovie6;
    @BindView(R.id.movie_rl6)
    AutoRelativeLayout movieRl6;
    @BindView(R.id.searchLl)
    LinearLayout searchLl;
    @BindView(R.id.collectLl)
    LinearLayout collectLl;
    @BindView(R.id.historyLl)
    LinearLayout historyLl;
    @BindView(R.id.text_general_tel)
    AutoMarqueeTextView textGeneralTel;

    private List<Video> videolist;
    public static String currentMovie = "";

    @Override
    protected int getContentResId() {
        return R.layout.activity_movie;
    }

    @Override
    protected void initView() {
        movieRl1.setOnClickListener(this);
        movieRl2.setOnClickListener(this);
        movieRl3.setOnClickListener(this);
        movieRl4.setOnClickListener(this);
        movieRl5.setOnClickListener(this);
        movieRl6.setOnClickListener(this);
        searchLl.setOnClickListener(this);
        collectLl.setOnClickListener(this);
        historyLl.setOnClickListener(this);
        textGeneralTel.setText(getString(R.string.tel) + "11111111");
    }

    @Override
    protected void initData() {
        videolist = new ArrayList<>();
        currentMovie = Constant.MENU_TYPE_MOVIE;
        Glide.with(MovieActivivty.this).load(R.mipmap.hotmovie).into(imgMovie1);
//        Glide.with(MovieActivivty.this).load().into(imgMovie2);
        Glide.with(MovieActivivty.this).load(R.mipmap.movie).into(imgMovie3);
        Glide.with(MovieActivivty.this).load(R.mipmap.carton).into(imgMovie4);
        Glide.with(MovieActivivty.this).load(R.mipmap.tvplay).into(imgMovie5);
        Glide.with(MovieActivivty.this).load(R.mipmap.variety).into(imgMovie6);
    }


    @Override
    public void onClick(View v) {
        Intent intent = null;
        final ProgressDialog dialog = new ProgressDialog(MovieActivivty.this);
        dialog.setMessage(getString(R.string.loading_tvlist));
        dialog.setIndeterminate(false);
        dialog.setCancelable(true);
        switch (v.getId()) {
            case R.id.movie_rl1:
                ShowAllMovie(dialog);
                currentMovie = Constant.MENU_TYPE_MOVIE;
                intent = new Intent(MovieActivivty.this,MovieListActivivty.class);
                break;
//            case R.id.movie_rl2:
//                ShowAllMovie();
//                currentMovie = Constant.MENU_TYPE_MOVIE;
//                break;
            case R.id.movie_rl3:
                ShowMovie(dialog);
                currentMovie = Constant.MENU_TYPE_MOVIE;
                intent = new Intent(MovieActivivty.this,MovieListActivivty.class);
                break;
            case R.id.movie_rl4:
                ShowAnimation(dialog);
                currentMovie = Constant.MENU_TYPE_ANIMATION;
                intent = new Intent(MovieActivivty.this,MovieListActivivty.class);
                break;
            case R.id.movie_rl5:
                currentMovie = Constant.MENU_TYPE_SERIES;
                ShowTv(dialog);
                break;
            case R.id.movie_rl6:
                ShowVariety(dialog);
                currentMovie = Constant.MENU_TYPE_VARIETY;
                intent = new Intent(MovieActivivty.this,MovieListActivivty.class);
                break;
//            case R.id.searchLl:
//                intent = new Intent(MovieActivivty.this, SearchByInitialActivity.class);
//                break;
//            case R.id.collectLl:
//                intent = new Intent(MovieActivivty.this, TeleplayTypeActivity.class);
//                intent.putExtra("searchtype", Constant.TEXT_COLLECT);
//                break;
//            case R.id.historyLl:
//                intent = new Intent(MovieActivivty.this, TeleplayTypeActivity.class);
//                intent.putExtra("searchtype", Constant.TEXT_RECENT);
//                break;
        }
        if (intent != null) {
            startActivity(intent);
        }
    }

    /**
     * 显示全部电影/最新电影
     */
    public void ShowAllMovie(final Dialog dialog) {

    }

    /**
     * 显示电影
     */
    public void ShowMovie(final Dialog dialog) {

    }

    /**
     * 显示动漫
     */
    public void ShowAnimation(final Dialog dialog) {

    }

    /**
     * 显示电视剧
     */
    public void ShowTv(final Dialog dialog) {

    }

    /**
     * 显示综艺
     */
    public void ShowVariety(final Dialog dialog) {
//        dialog.show();
//        if (!dialog.isShowing()) {
//            return;
//        }
//        teleplayPersenter.loadTeleplayVarietyView(new MainTeleplayPresenter.TeleplayListView() {
//            @Override
//            public void showTeleplayList(List<Video> teleplayList) {
//                if (teleplayList.size() > 0) {
//                    dialog.dismiss();
//                    Intent intent = new Intent(MovieActivivty.this, MovieListActivivty.class);
//                    intent.putExtra("videolist", (Serializable) teleplayList);
//                    startActivity(intent);
//                    return;
//                }
//                if (!dialog.isShowing()) {
//                    return;
//                } else {
//                    new Thread(new Runnable() {
//                        @Override
//                        public void run() {
//                            try {
//                                Thread.sleep(3000);
//                                dialog.dismiss();
//                                startActivity(new Intent(MovieActivivty.this, MovieListActivivty.class));
//                            } catch (InterruptedException e) {
//                                e.printStackTrace();
//                            }
//                        }
//                    }).start();
//                }
//            }
//
//            @Override
//            public void showFailed(final String msg) {
//                Toast.makeText(MovieActivivty.this, msg.toString(), Toast.LENGTH_SHORT).show();
//                new Thread(new Runnable() {
//                    @Override
//                    public void run() {
//                        try {
//                            Thread.sleep(3000);
//                            dialog.dismiss();
//                            startActivity(new Intent(MovieActivivty.this, MovieListActivivty.class));
//                        } catch (InterruptedException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }).start();
//            }
//        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        videolist.clear();
    }

}
